package 爆刷leetcode.balabala;

/**
 * @Author yaya
 * @Create 2024/5/25 11:33
 * Description:
 */
public class Merge {

}

class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int[] reslut = new int[m + n];

        int left = 0;
        int right = 0;

        while (left < m && right < n){
            reslut[left + right] = nums1[left] < nums2[right] ? nums1[left++] : nums2[right++];
        }

        if (left == m) {
            while (right < n)
                reslut[left + right] = nums2[right++];
        }


        if (right == n) {
            while (left < m)
                reslut[left + right] = nums1[left++];
        }

        for (int i = 0; i < m + n; i++) {
            nums1[i] =  reslut[i];
        }
    }
}
